package com.gec.anan.driver;

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MinoDemo {
    public static void main(String[] args) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        MinioClient client = MinioClient.builder()
                .endpoint("http://192.168.137.131:9000")
                .credentials("admin", "admin123456")
                .build();
        boolean isSuccess = client.bucketExists(BucketExistsArgs.builder().bucket("yuntu").build());
        if(!isSuccess){
            client.makeBucket(MakeBucketArgs.builder().bucket("yuntu").build());
        }else {
            System.out.println("存在");
        }
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\86187\\Pictures\\Camera Roll\\R-C.png");
        client.putObject(
                PutObjectArgs.builder()
                        .bucket("yuntu")
                        .object("R-C.png")
                        .stream(fileInputStream,fileInputStream.available(),-1)
                        .build());
        String url = "http://192.168.137.131:9000/yuntu/R-C.png";
        System.out.println(url);
    }
}
